package com.example.api;

import com.example.pojo.TbUser;
import com.example.service.*;
import com.example.util.Response;
import com.example.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Description:
 * Param:
 * return:
 * Author:20201003095余方圆*
 * Date:2022/12/24
 */
@RestController
@ResponseBody
@Api(tags = "用户管理接口")
public class TbUserAPI {
    @Autowired
    private TbUserService tbUserService;

    //查询所有书籍销售相关信息
    @GetMapping("/users")
    @ApiOperation("查询所有用户信息")
    public ResponseResult<List<TbUser>> getAllUser() {

        List<TbUser> tbuserList = tbUserService.findTbUsers();
//        return bookList;
        System.out.println(tbuserList);
        return Response.createOkResp("查询成功");
    }

    @GetMapping("/users/{user_Name}")
    @ApiOperation("根据用户名字查询用户信息")
    public ResponseResult<TbUser> getbyUserName(@PathVariable("user_Name") String user_Name) {
        TbUser tbUser = tbUserService.findTbUserByUserName(user_Name);
        return Response.createOkResp("查询成功",tbUser);
    }

    @PostMapping("/users")
    @ApiOperation("添加用户信息")
    public ResponseResult<TbUser> addUser(String user_name,String login_name,String password) {
        int num = tbUserService.addTbUser(user_name,login_name,password);
        System.out.println(num);
        return Response.createOkResp("添加成功");
    }

    @PutMapping("/users")
    @ApiOperation("修改用户信息")
    public ResponseResult<Map> updateTbUser(TbUser tbUser) {
        int num = tbUserService.updateTbUser(tbUser);
        System.out.println(num);
        return Response.createOkResp("修改成功");
    }

    @ApiOperation("删除用户信息，包括详细信息")
    @DeleteMapping("/users/{id}")
    public ResponseResult<Map> delete(@PathVariable("id") Long id) {
        int num = tbUserService.deleteTbUser(id);
        return Response.createOkResp("删除成功");
    }


}
